#include <ptgui/ptgui.h>
#include <ptgui/pagectl.h>
#include <ptgui/pages/page.h>
#include <SDL/SDL.h>

/*	Event Process Table	*/
static	void ptgui_page_entry_handler(ptgui_page_entry_type_t Requese)
{
	if (PTGUI_PAGE_PREPARE_FST == Requese) {
		//Do Nothing
	}
	else if (PTGUI_PAGE_PREPARE_ALL == Requese) {
	}
	else if (PTGUI_PAGE_TERMINATE_ALL == Requese) {
		//Do Nothing
	}
	else if (PTGUI_PAGE_TERMINATE_LST == Requese) {
	}
	else {
		//Do Nothing
	}
}

static	ptgui_page_control_t nvdProcPsvUpdateEndCancel(ptgui_event_t *EventCode)
{
	return	PTGUI_PAGE_TRAN_RETURN_REQUEST(FP_PAGE_DRAW);
}

static	ptgui_page_sw_state_t nusGetViewPsvUpdateEndCancel(ptgui_page_switch_view_t *Switch)
{
	return	PAGE_SW_STAT_VISIBLE;
}
extern void DrawPict(SDL_Surface *screen, char *bmpfile,
					int speedy, int flip, int nofade);
extern SDL_Surface *screen;
extern int speedy, flip, nofade;
static ptgui_page_control_t ptgui_page_render_handler(ptgui_event_t* event)
{
	Uint32 c_white = SDL_MapRGB(screen->format, 255,255,255);
	Uint32 c_gray = SDL_MapRGB(screen->format, 200,200,200);
	Uint32 c_dgray= SDL_MapRGB(screen->format, 64,64,64);
	Uint32 c_cyan = SDL_MapRGB(screen->format, 32,255,255);
	int i;
	for (i = 0; i < 100; i ++)
	{
	SDL_DrawPixel(screen, 510,410+i, c_white);
	SDL_DrawPixel(screen, 520,420+i,
			 SDL_MapRGB(screen->format, 255,0,0));
	SDL_DrawPixel(screen, 530,430+i,
			 SDL_MapRGB(screen->format, 0,255,0));
	SDL_DrawPixel(screen, 540,440+i,
			 SDL_MapRGB(screen->format, 0,0,255));
	}

	SDL_DrawLine(screen, 100,100, 30,0, c_white);
	SDL_DrawLine(screen, 30,0, 100,100, c_white);

	SDL_DrawLine(screen, 100,100, 30,0, c_white);
	SDL_DrawLine(screen, 30,0, 100,100, c_white);
	SDL_DrawLine(screen, 0,0, 100,100, c_white);
	SDL_DrawLine(screen, 100,100, 300,200, c_white);
	SDL_DrawLine(screen, 200,300, 250,400,
				SDL_MapRGB(screen->format, 128,128,255));
	SDL_DrawLine(screen, 500,50, 600,70,
				SDL_MapRGB(screen->format, 128,255,128));
	SDL_DrawLine(screen, 500,50, 600,70,
				SDL_MapRGB(screen->format, 128,255,128));
	SDL_DrawCircle(screen, 100,100, 50, c_white);

	/*-------------*/
	SDL_DrawCircle(screen, 150,150, 5, c_white);
	SDL_DrawCircle(screen, 150,150, 4,
				 SDL_MapRGB(screen->format, 64,64,64));
	SDL_DrawCircle(screen, 150,150, 3,
				 SDL_MapRGB(screen->format, 255,0,0));
	SDL_DrawCircle(screen, 150,150, 2,
				 SDL_MapRGB(screen->format, 0,255,0));
	SDL_DrawCircle(screen, 150,150, 1,
				 SDL_MapRGB(screen->format, 0,0,255));
	/*-------------*/

	SDL_DrawLine(screen, 500,100, 600,120,
				SDL_MapRGB(screen->format, 128,255,128));
	SDL_DrawCircle(screen, 601,121, 2, c_white);

	SDL_DrawCircle(screen, 400,200, 2, c_white);
	SDL_DrawLine(screen, 400,200, 409,200, c_white);
	SDL_DrawCircle(screen, 409,200, 2, c_white);
	SDL_DrawLine(screen, 400,200, 400,250, c_white);
	SDL_DrawCircle(screen, 400,250, 2, c_white);
	SDL_DrawLine(screen, 409,200, 400,250, c_white);


	SDL_DrawLine(screen, 400,300, 409,300, c_gray);
	SDL_DrawLine(screen, 400,300, 400,350, c_gray);
	SDL_DrawLine(screen, 409,300, 400,350, c_dgray);
	SDL_DrawRect(screen, 398,298, 4,4, c_cyan);
	SDL_DrawRect(screen, 407,298, 4,4, c_cyan);
	SDL_DrawRect(screen, 398,348, 4,4, c_cyan);

	SDL_DrawHLine(screen, 10,400, 50, c_white);
	SDL_DrawVLine(screen, 60,400, 360, c_white);
	SDL_DrawRect(screen, 500,400, 50,50, c_white);
	SDL_DrawPixel(screen, 510,410, c_white);
	SDL_DrawPixel(screen, 520,420,
			 SDL_MapRGB(screen->format, 255,0,0));
	SDL_DrawPixel(screen, 530,430,
			 SDL_MapRGB(screen->format, 0,255,0));
	SDL_DrawPixel(screen, 540,440,
			 SDL_MapRGB(screen->format, 0,0,255));


	SDL_DrawEllipse(screen, 100,300, 60,30, c_white);

	SDL_DrawFillEllipse(screen, 300,300, 30,60,
			   SDL_MapRGB(screen->format, 64,64,200));
	SDL_DrawEllipse(screen, 300,300, 30,60,
			   SDL_MapRGB(screen->format, 255,0,0));

	SDL_DrawRound(screen, 200,20, 70,50, 10, c_white);
	SDL_DrawRound(screen, 300,20, 70,50, 20,
			 SDL_MapRGB(screen->format, 255,0,0));
	SDL_DrawFillRound(screen, 390,20, 70,50, 20,
				 SDL_MapRGB(screen->format, 255,0,0));
	SDL_DrawRound(screen, 390,20, 70,50, 20, c_cyan);

	/*SDL_DrawRound(screen, 500,400, 5,3, 4, c_cyan);*/

	SDL_DrawRect(screen, 499,199, 52,72,
			SDL_MapRGB(screen->format, 255,255,0));
	SDL_DrawFillRect(screen, 500,200, 50,70,
				SDL_MapRGB(screen->format, 64,200,64));

	SDL_DrawFillCircle(screen, 500,330, 30, c_cyan);

	return PTGUI_PAGE_TRAN_KEEP_FLAT;
}

static ptgui_page_control_t ptgui_page_frame_handler(ptgui_event_t* event)
{
	return PTGUI_PAGE_TRAN_KEEP_FLAT;
}

static ptgui_page_control_t ptgui_page_mouse_handler(ptgui_event_t* event)
{
	ptgui_page_key_event_break();
	return PTGUI_PAGE_TRAN_CALL_REQUEST(FP_PAGE_SIMPLE);
}
/*	Opening Cancel Key Definition	*/
PTGUI_PAGE_DEF_SW_VIEW(TswPsvUpdateEndCancel, nvdProcPsvUpdateEndCancel, nusGetViewPsvUpdateEndCancel, 0, 0, 0,
					   (KEY_ON_DO));

/*	Static Key Table	*/
PTGUI_PAGE_BEGIN_REF_SW_VIEW_TABLE 
PTGUI_PAGE_REF_SW_VIEW(TswPsvUpdateEndCancel),
PTGUI_PAGE_END_REF_SW_VIEW_TABLE(FP_PAGE_DRAW);

PTGUI_PAGE_BEGIN_DEF_EVENT_ACCEPT 
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_PAINT, ptgui_page_render_handler),
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_FRAME, ptgui_page_frame_handler),
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_MOUSE_BUTTON, ptgui_page_mouse_handler),
PTGUI_PAGE_END_DEF_EVENT_ACCEPT;

PTGUI_PAGE_DEF_PAGECELL(FP_PAGE_DRAW);